package com.gjw.blog.config;

import com.gjw.blog.templates.HotsTemplate;
import com.gjw.blog.templates.PostsTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @author gjw19
 * @since 2019/11/7.
 */
@Configuration
public class FreemarkerConfig {

    @Autowired
    private freemarker.template.Configuration configuration;

    @Autowired
    private ApplicationContext applicationContext;

    @PostConstruct
    public void setUp() {
        configuration.setSharedVariable("posts", applicationContext.getBean(PostsTemplate.class));
        configuration.setSharedVariable("hots", applicationContext.getBean(HotsTemplate.class));
    }
}
